package com.jz.netthings.application.stockManage.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.jz.netthings.application.stockManage.bean.ConsumablesTemplate;
import com.jz.netthings.application.stockManage.service.ConsumablesTemplateService;
import com.jz.netthings.exception.AdscmSystemException;
import com.jz.netthings.support.SimpleCoreResponse;
import com.jz.netthings.utils.AdscmDateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * <p>
 * 耗材模板 前端控制器
 * </p>
 *
 * @author yangyunyun
 * @since 2019-07-29
 */
@RestController
@RequestMapping("/adscm/application/consumablesTemplate")
public class ConsumablesTemplateController {

    @Autowired
    ConsumablesTemplateService consumablesTemplateService;

    /**
     * 新增耗材模板
     * @param consumablesTemplate
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/insertTemplate")
    public SimpleCoreResponse insertTemplate(@RequestBody ConsumablesTemplate consumablesTemplate) throws AdscmSystemException {

        consumablesTemplateService.insert(consumablesTemplate);
        return new SimpleCoreResponse("200","新增成功",null);
    }

    /**
     * 查询所有耗材模板
     * @param exceptOverdue 是否除开过期的耗材模板
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/selectAll")
    public SimpleCoreResponse selectAll(Boolean exceptOverdue) throws AdscmSystemException {

        Wrapper<ConsumablesTemplate> wrapper = null;
        if(exceptOverdue != null && exceptOverdue){
            wrapper = new EntityWrapper<>();
            wrapper.le("validityEnd", AdscmDateUtils.getNowOnlyDateFomat1(new Date()));
        }

        return new SimpleCoreResponse("200","查询成功",consumablesTemplateService.selectList(wrapper));
    }

}

